#ifndef _G7221_DATA_H_
#define _G7221_DATA_H_

#include <stdint.h>

/*****************************************************************************
 * MAIN
 *****************************************************************************/
#define MAX_DCT_LENGTH      640


/*****************************************************************************
 * IMLT
 *****************************************************************************/

/* vs refdec: this window seems based on float refdec with a scale:
 *   for (i = 0; i < 640; i++)
 *       window[i] = floor(sin((PI/2.0) * (i + 0.5) / 640) * 32767.0)
 * while the original int refdec table uses an altered formula? (smaller values) */
static const int16_t imlt_samples_window[MAX_DCT_LENGTH] = { /* "Out_Window"? */
    40,    120,   201,   281,   361,   442,   522,   603,   683,   763,
    844,   924,   1005,  1085,  1165,  1246,  1326,  1406,  1487,  1567,
    1647,  1728,  1808,  1888,  1969,  2049,  2129,  2209,  2290,  2370,
    2450,  2530,  2610,  2691,  2771,  2851,  2931,  3011,  3091,  3171,
    3251,  3331,  3411,  3491,  3571,  3651,  3731,  3811,  3891,  3971,
    4050,  4130,  4210,  4290,  4369,  4449,  4529,  4608,  4688,  4768,
    4847,  4927,  5006,  5086,  5165,  5245,  5324,  5403,  5483,  5562,
    5641,  5720,  5799,  5879,  5958,  6037,  6116,  6195,  6274,  6353,
    6431,  6510,  6589,  6668,  6747,  6825,  6904,  6982,  7061,  7140,
    7218,  7296,  7375,  7453,  7531,  7610,  7688,  7766,  7844,  7922,
    8000,  8078,  8156,  8234,  8312,  8390,  8467,  8545,  8623,  8700,
    8778,  8855,  8932,  9010,  9087,  9164,  9242,  9319,  9396,  9473,
    9550,  9627,  9703,  9780,  9857,  9934,  10010, 10087, 10163, 10240,
    10316, 10392, 10469, 10545, 10621, 10697, 10773, 10849, 10925, 11001,
    11076, 11152, 11227, 11303, 11378, 11454, 11529, 11604, 11680, 11755,
    11830, 11905, 11980, 12054, 12129, 12204, 12278, 12353, 12427, 12502,
    12576, 12650, 12724, 12798, 12872, 12946, 13020, 13094, 13168, 13241,
    13315, 13388, 13462, 13535, 13608, 13681, 13754, 13827, 13900, 13973,
    14046, 14118, 14191, 14263, 14335, 14408, 14480, 14552, 14624, 14696,
    14768, 14840, 14911, 14983, 15054, 15126, 15197, 15268, 15339, 15410,
    15481, 15552, 15623, 15693, 15764, 15834, 15905, 15975, 16045, 16115,
    16185, 16255, 16325, 16395, 16464, 16534, 16603, 16672, 16742, 16811,
    16880, 16948, 17017, 17086, 17154, 17223, 17291, 17360, 17428, 17496,
    17564, 17632, 17699, 17767, 17834, 17902, 17969, 18036, 18103, 18170,
    18237, 18304, 18371, 18437, 18504, 18570, 18636, 18702, 18768, 18834,
    18900, 18966, 19031, 19096, 19162, 19227, 19292, 19357, 19422, 19486,
    19551, 19616, 19680, 19744, 19808, 19872, 19936, 20000, 20064, 20127,
    20190, 20254, 20317, 20380, 20443, 20506, 20568, 20631, 20693, 20756,
    20818, 20880, 20942, 21003, 21065, 21127, 21188, 21249, 21311, 21372,
    21432, 21493, 21554, 21614, 21675, 21735, 21795, 21855, 21915, 21975,
    22034, 22094, 22153, 22212, 22271, 22330, 22389, 22448, 22506, 22565,
    22623, 22681, 22739, 22797, 22854, 22912, 22969, 23027, 23084, 23141,
    23198, 23254, 23311, 23367, 23424, 23480, 23536, 23592, 23648, 23703,
    23759, 23814, 23869, 23924, 23979, 24034, 24088, 24143, 24197, 24251,
    24305, 24359, 24413, 24466, 24520, 24573, 24626, 24679, 24732, 24785,
    24837, 24890, 24942, 24994, 25046, 25098, 25149, 25201, 25252, 25303,
    25354, 25405, 25456, 25506, 25557, 25607, 25657, 25707, 25757, 25806,
    25856, 25905, 25954, 26003, 26052, 26101, 26150, 26198, 26246, 26294,
    26342, 26390, 26437, 26485, 26532, 26579, 26626, 26673, 26720, 26766,
    26812, 26859, 26905, 26950, 26996, 27042, 27087, 27132, 27177, 27222,
    27267, 27311, 27355, 27400, 27444, 27488, 27531, 27575, 27618, 27661,
    27704, 27747, 27790, 27832, 27875, 27917, 27959, 28001, 28042, 28084,
    28125, 28167, 28208, 28248, 28289, 28330, 28370, 28410, 28450, 28490,
    28529, 28569, 28608, 28647, 28686, 28725, 28764, 28802, 28840, 28878,
    28916, 28954, 28992, 29029, 29066, 29103, 29140, 29177, 29213, 29250,
    29286, 29322, 29358, 29393, 29429, 29464, 29499, 29534, 29569, 29603,
    29638, 29672, 29706, 29740, 29773, 29807, 29840, 29873, 29906, 29939,
    29972, 30004, 30036, 30068, 30100, 30132, 30163, 30195, 30226, 30257,
    30288, 30318, 30349, 30379, 30409, 30439, 30468, 30498, 30527, 30556,
    30585, 30614, 30643, 30671, 30699, 30727, 30755, 30783, 30810, 30838,
    30865, 30892, 30918, 30945, 30971, 30997, 31023, 31049, 31075, 31100,
    31125, 31150, 31175, 31200, 31224, 31249, 31273, 31297, 31320, 31344,
    31367, 31390, 31413, 31436, 31459, 31481, 31503, 31525, 31547, 31569,
    31590, 31612, 31633, 31653, 31674, 31695, 31715, 31735, 31755, 31775,
    31794, 31814, 31833, 31852, 31871, 31889, 31907, 31926, 31944, 31961,
    31979, 31997, 32014, 32031, 32048, 32064, 32081, 32097, 32113, 32129,
    32145, 32160, 32176, 32191, 32206, 32220, 32235, 32249, 32263, 32277,
    32291, 32304, 32318, 32331, 32344, 32357, 32369, 32382, 32394, 32406,
    32418, 32429, 32441, 32452, 32463, 32474, 32484, 32495, 32505, 32515,
    32525, 32535, 32544, 32553, 32562, 32571, 32580, 32588, 32597, 32605,
    32613, 32620, 32628, 32635, 32642, 32649, 32656, 32662, 32669, 32675,
    32681, 32686, 32692, 32697, 32702, 32707, 32712, 32717, 32721, 32725,
    32729, 32733, 32736, 32740, 32743, 32746, 32749, 32751, 32753, 32756,
    32758, 32759, 32761, 32762, 32764, 32765, 32765, 32766, 32766, 32766,
};

/* set helper for DCT-IV optimizations (code seem to stop at 174) */
static const uint8_t imlt_set1_table[176] = {
    1, 1, 1, 1, 1, 1, 3, 1, 2, 0, 1, 1, 3, 1, 1, 1, 
    1, 1, 3, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 1,
    3, 1, 3, 1, 1, 1, 1, 1, 3, 1, 2, 0, 1, 1, 3, 1,
    1, 1, 1, 1, 3, 1, 3, 1, 3, 1, 1, 1, 1, 1, 3, 1,
    1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 3, 1,
    1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1,
    3, 1, 3, 1, 3, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1,
    3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 3, 1, 1, 1, 1, 1,
    3, 1, 3, 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 3, 1,
    1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1,
    3, 1, 3, 1, 3, 1, 1, 1, 1, 1, 3, 1, 2, 0, 0, 0,
};
static const uint8_t imlt_set2_table[44] = {
    1, 3, 1, 1, 3, 3, 3, 1, 1, 3, 1, 1, 3, 1, 1, 3,
    3, 3, 1, 1, 3, 1, 1, 3, 1, 1, 3, 3, 3, 1, 1, 3,
    2, 1, 3, 1, 1, 3, 1, 1, 3, 2, 1, 1,
};

/* vs refdec: bigger values calculated differently (unsure how), probably:
 *   for (i = 0; i < size; i++)
 *      cos/sin( (PI / (4 * size)) * (i + 0.5) * unknown_scale )
 * Originally were multiple separate tables, but here they are fused into one
 * (could be cleaned up, may be a compiler optimization)
 * Note this uses *unsigned* int16s, for temp vars we can use ints */
static const uint16_t imlt_cos_tables[636] = {
    /* imlt_cos_table_64[320] (640/2) */
    65535,   65535,   65534,   65533,   65532,   65530,   65527,   65524,
    65521,   65518,   65514,   65509,   65505,   65500,   65494,   65488,
    65482,   65475,   65468,   65460,   65453,   65444,   65436,   65427,
    65417,   65407,   65397,   65386,   65375,   65364,   65352,   65340,
    65327,   65314,   65301,   65287,   65273,   65258,   65243,   65228,
    65212,   65196,   65179,   65162,   65145,   65127,   65109,   65091,
    65072,   65052,   65033,   65013,   64992,   64971,   64950,   64928,
    64906,   64884,   64861,   64838,   64814,   64790,   64766,   64741,
    64716,   64690,   64665,   64638,   64611,   64584,   64557,   64529,
    64501,   64472,   64443,   64414,   64384,   64353,   64323,   64292,
    64261,   64229,   64197,   64164,   64131,   64098,   64064,   64030,
    63996,   63961,   63925,   63890,   63854,   63817,   63781,   63743,
    63706,   63668,   63630,   63591,   63552,   63512,   63473,   63432,
    63392,   63351,   63309,   63268,   63225,   63183,   63140,   63097,
    63053,   63009,   62965,   62920,   62875,   62829,   62783,   62737,
    62690,   62643,   62596,   62548,   62500,   62451,   62402,   62353,
    62303,   62253,   62203,   62152,   62100,   62049,   61997,   61945,
    61892,   61839,   61785,   61732,   61677,   61623,   61568,   61513,
    61457,   61401,   61344,   61288,   61231,   61173,   61115,   61057,
    60998,   60939,   60880,   60820,   60760,   60700,   60639,   60578,
    60516,   60454,   60392,   60329,   60266,   60203,   60139,   60075,
    60011,   59946,   59881,   59815,   59749,   59683,   59616,   59549,
    59482,   59414,   59346,   59278,   59209,   59140,   59070,   59000,
    58930,   58860,   58789,   58718,   58646,   58574,   58502,   58429,
    58356,   58283,   58209,   58135,   58060,   57986,   57910,   57835,
    57759,   57683,   57606,   57530,   57452,   57375,   57297,   57219,
    57140,   57061,   56982,   56902,   56822,   56742,   56661,   56580,
    56499,   56417,   56335,   56253,   56170,   56087,   56004,   55920,
    55836,   55752,   55667,   55582,   55497,   55411,   55325,   55238,
    55152,   55065,   54977,   54889,   54801,   54713,   54624,   54535,
    54446,   54356,   54266,   54176,   54085,   53994,   53903,   53811,
    53719,   53627,   53534,   53441,   53348,   53255,   53161,   53066,
    52972,   52877,   52782,   52686,   52591,   52494,   52398,   52301,
    52204,   52107,   52009,   51911,   51813,   51714,   51615,   51516,
    51416,   51316,   51216,   51116,   51015,   50914,   50812,   50710,
    50608,   50506,   50403,   50301,   50197,   50094,   49990,   49886,
    49781,   49676,   49571,   49466,   49360,   49254,   49148,   49042,
    48935,   48828,   48720,   48612,   48504,   48396,   48288,   48179,
    48069,   47960,   47850,   47740,   47630,   47519,   47408,   47297,
    47186,   47074,   46962,   46849,   46737,   46624,   46511,   46397,
    /* imlt_cos_table_32[160] (640/4) (seems unused) */
    65535,   65534,   65531,   65526,   65520,   65512,   65502,   65491,
    65478,   65464,   65448,   65431,   65412,   65392,   65370,   65346,
    65321,   65294,   65265,   65235,   65204,   65171,   65136,   65100,
    65062,   65023,   64982,   64939,   64895,   64850,   64802,   64754,
    64703,   64651,   64598,   64543,   64486,   64428,   64369,   64307,
    64245,   64180,   64115,   64047,   63978,   63908,   63836,   63762,
    63687,   63610,   63532,   63452,   63371,   63289,   63204,   63118,
    63031,   62942,   62852,   62760,   62667,   62572,   62475,   62377,
    62278,   62177,   62075,   61971,   61865,   61759,   61650,   61540,
    61429,   61316,   61202,   61086,   60969,   60850,   60730,   60608,
    60485,   60361,   60235,   60107,   59978,   59848,   59716,   59583,
    59448,   59312,   59174,   59035,   58895,   58753,   58610,   58465,
    58319,   58172,   58023,   57873,   57721,   57568,   57414,   57258,
    57101,   56942,   56782,   56621,   56458,   56294,   56129,   55962,
    55794,   55624,   55454,   55282,   55108,   54933,   54757,   54580,
    54401,   54221,   54040,   53857,   53673,   53488,   53301,   53114,
    52925,   52734,   52543,   52350,   52155,   51960,   51763,   51565,
    51366,   51166,   50964,   50761,   50557,   50352,   50146,   49938,
    49729,   49519,   49307,   49095,   48881,   48666,   48450,   48233,
    48015,   47795,   47575,   47353,   47130,   46906,   46680,   46454,
    /* imlt_cos_table_16[80] (640/8) */
    65535,   65528,   65516,   65497,   65472,   65440,   65402,   65358,
    65307,   65251,   65188,   65118,   65043,   64961,   64873,   64778,
    64678,   64571,   64458,   64338,   64213,   64081,   63943,   63799,
    63649,   63493,   63330,   63162,   62987,   62806,   62619,   62427,
    62228,   62023,   61812,   61595,   61373,   61144,   60910,   60669,
    60423,   60171,   59913,   59650,   59380,   59105,   58824,   58538,
    58246,   57948,   57645,   57336,   57022,   56702,   56376,   56046,
    55709,   55368,   55021,   54669,   54311,   53949,   53581,   53208,
    52830,   52446,   52058,   51665,   51266,   50863,   50455,   50042,
    49624,   49201,   48774,   48342,   47905,   47464,   47018,   46567,
    /* imlt_cos_table_8[40] (640/16) */
    65532,   65507,   65457,   65381,   65280,   65154,   65002,   64826,
    64625,   64399,   64148,   63872,   63571,   63247,   62897,   62524,
    62126,   61705,   61259,   60790,   60298,   59782,   59243,   58682,
    58098,   57491,   56862,   56212,   55539,   54846,   54131,   53395,
    52639,   51862,   51065,   50249,   49413,   48558,   47685,   46793,
    /* imlt_cos_table_4[20] (640/32) */
    65523,   65422,   65220,   64917,   64515,   64013,   63412,   62714,
    61918,   61028,   60043,   58965,   57797,   56540,   55195,   53765,
    52253,   50660,   48988,   47241,   
    /* imlt_cos_table_2[10] (640/64) */
    65485,   65081,   64276,   63075,   61485,   59516,   57179,   54491,
    51466,   48124,
    /* imlt_cos_table_1[5] (640/128) */
    65333,   63725,   60547,   55878,   49833,
    /* extra */
    0,
};

/* see cos table info */
static const uint16_t imlt_sin_tables[636] = { /* "sin_table" */
    /* imlt_sin_table_64[320] (640/2) */
       80,     241,     402,     562,     723,     884,    1045,    1206,
     1367,    1527,    1688,    1849,    2010,    2171,    2331,    2492,
     2653,    2814,    2974,    3135,    3296,    3456,    3617,    3777,
     3938,    4098,    4259,    4420,    4580,    4740,    4901,    5061,
     5222,    5382,    5542,    5702,    5863,    6023,    6183,    6343,
     6503,    6663,    6823,    6983,    7143,    7303,    7463,    7623,
     7782,    7942,    8102,    8261,    8421,    8580,    8740,    8899,
     9058,    9218,    9377,    9536,    9695,    9854,   10013,   10172,
    10331,   10490,   10649,   10807,   10966,   11124,   11283,   11441,
    11600,   11758,   11916,   12074,   12232,   12390,   12548,   12706,
    12864,   13021,   13179,   13337,   13494,   13651,   13809,   13966,
    14123,   14280,   14437,   14594,   14751,   14907,   15064,   15220,
    15377,   15533,   15689,   15845,   16001,   16157,   16313,   16469,
    16625,   16780,   16936,   17091,   17246,   17401,   17556,   17711,
    17866,   18021,   18175,   18330,   18484,   18638,   18793,   18947,
    19101,   19254,   19408,   19562,   19715,   19868,   20022,   20175,
    20328,   20481,   20633,   20786,   20938,   21091,   21243,   21395,
    21547,   21699,   21851,   22002,   22154,   22305,   22456,   22607,
    22758,   22909,   23059,   23210,   23360,   23511,   23661,   23811,
    23960,   24110,   24259,   24409,   24558,   24707,   24856,   25005,
    25153,   25302,   25450,   25598,   25746,   25894,   26042,   26189,
    26337,   26484,   26631,   26778,   26925,   27071,   27217,   27364,
    27510,   27656,   27801,   27947,   28092,   28238,   28383,   28528,
    28672,   28817,   28961,   29105,   29250,   29393,   29537,   29681,
    29824,   29967,   30110,   30253,   30395,   30538,   30680,   30822,
    30964,   31106,   31247,   31388,   31529,   31670,   31811,   31952,
    32092,   32232,   32372,   32512,   32651,   32791,   32930,   33069,
    33208,   33346,   33485,   33623,   33761,   33898,   34036,   34173,
    34311,   34447,   34584,   34721,   34857,   34993,   35129,   35265,
    35400,   35535,   35670,   35805,   35940,   36074,   36208,   36342,
    36476,   36610,   36743,   36876,   37009,   37142,   37274,   37406,
    37538,   37670,   37801,   37933,   38064,   38195,   38325,   38456,
    38586,   38716,   38845,   38975,   39104,   39233,   39362,   39490,
    39618,   39746,   39874,   40002,   40129,   40256,   40383,   40509,
    40636,   40762,   40887,   41013,   41138,   41263,   41388,   41513,
    41637,   41761,   41885,   42009,   42132,   42255,   42378,   42501,
    42623,   42745,   42867,   42988,   43110,   43231,   43351,   43472,
    43592,   43712,   43832,   43951,   44070,   44189,   44308,   44426,
    44544,   44662,   44780,   44897,   45014,   45131,   45247,   45364,
    45480,   45595,   45711,   45826,   45941,   46055,   46170,   46284,
    /* imlt_sin_table_32[160] (640/4) */
      160,     482,     804,    1125,    1447,    1769,    2090,    2412,
     2733,    3055,    3376,    3697,    4018,    4339,    4660,    4981,
     5302,    5622,    5943,    6263,    6583,    6903,    7223,    7543,
     7862,    8181,    8501,    8819,    9138,    9456,    9775,   10093,
    10410,   10728,   11045,   11362,   11679,   11995,   12311,   12627,
    12943,   13258,   13573,   13887,   14202,   14515,   14829,   15142,
    15455,   15767,   16079,   16391,   16702,   17013,   17324,   17634,
    17943,   18253,   18561,   18870,   19177,   19485,   19792,   20098,
    20404,   20710,   21015,   21319,   21623,   21926,   22229,   22532,
    22833,   23135,   23435,   23736,   24035,   24334,   24633,   24930,
    25228,   25524,   25820,   26116,   26410,   26704,   26998,   27291,
    27583,   27874,   28165,   28455,   28745,   29033,   29321,   29609,
    29895,   30181,   30467,   30751,   31035,   31318,   31600,   31881,
    32162,   32442,   32721,   32999,   33277,   33554,   33830,   34105,
    34379,   34652,   34925,   35197,   35468,   35738,   36007,   36275,
    36543,   36810,   37075,   37340,   37604,   37867,   38129,   38390,
    38651,   38910,   39168,   39426,   39682,   39938,   40192,   40446,
    40699,   40950,   41201,   41451,   41699,   41947,   42194,   42439,
    42684,   42928,   43170,   43412,   43652,   43891,   44130,   44367,
    44603,   44839,   45073,   45306,   45537,   45768,   45998,   46227,
    /* imlt_sin_table_16[80] (640/8) */
      321,     965,    1608,    2251,    2894,    3536,    4179,    4821,
     5462,    6103,    6743,    7383,    8022,    8660,    9297,    9934,
    10569,   11204,   11837,   12469,   13100,   13730,   14359,   14986,
    15611,   16235,   16858,   17479,   18098,   18716,   19331,   19945,
    20557,   21167,   21775,   22381,   22984,   23586,   24185,   24782,
    25376,   25968,   26557,   27144,   27729,   28310,   28889,   29465,
    30038,   30609,   31176,   31741,   32302,   32860,   33415,   33967,
    34516,   35061,   35603,   36141,   36676,   37208,   37736,   38260,
    38780,   39297,   39810,   40319,   40825,   41326,   41823,   42317,
    42806,   43291,   43772,   44249,   44721,   45189,   45653,   46112,
    /* imlt_sin_table_8[40] (640/16) */
      643,    1929,    3215,    4500,    5783,    7063,    8341,    9616,
    10887,   12153,   13415,   14672,   15923,   17169,   18407,   19638,
    20862,   22078,   23285,   24483,   25672,   26851,   28020,   29178,
    30324,   31459,   32582,   33692,   34789,   35873,   36943,   37998,
    39039,   40065,   41076,   42070,   43049,   44011,   44956,   45883,
    /* imlt_sin_table_4[20] (640/32) */
     1286,    3858,    6423,    8979,   11520,   14044,   16547,   19024,
    21471,   23885,   26263,   28600,   30893,   33138,   35332,   37472,
    39554,   41575,   43532,   45422,    
    /* imlt_sin_table_2[10] (640/64) */
     2572,    7702,   12785,   17789,   22683,   27437,   32022,   36409,
    40572,   44485,    
    /* imlt_sin_table_1[5] (640/128) */
    5141,   15299,   25079,   34242,   42562,
    /* extra */
    0,
};


/*****************************************************************************
 * UNPACK
 *****************************************************************************/

#define REGION_POWER_TABLE_SIZE 64
#define REGION_POWER_TABLE_NUM_NEGATIVES 24

#define NUM_CATEGORIZATION_CONTROL_BITS 5
#define NUM_CATEGORIZATION_CONTROL_POSSIBILITIES 32

#define NUM_CATEGORIES  8
#define DRP_DIFF_MIN  12 /* used as negative */
//#define DRP_DIFF_MAX  11
#define NUM_BINS  16
//#define MAX_VECTOR_INDICES  625
#define MAX_VECTOR_DIMENSION  5
//#define ABS_REGION_POWER_LEVELS  32
#define NUMBER_OF_REGIONS  28
#define REGION_SIZE  20
#define DIFF_REGION_POWER_LEVELS  24

/* Default scale factor is a bit high due to something something and this compensates
 * (using 9-1 may sound better since most Siren14 BNSF get a bit clippy) */
#define ESF_ADJUSTMENT_TO_RMS_INDEX  (9-2)


/* vs refdec: has region 0 (unused, all 0s) and regions>13 (repeats of region 13) so they were removed.
 * 2nd index only went to DIFF_REGION_POWER_LEVELS-1 and last was added (all 0s though so probably unused). */
static const int16_t differential_region_power_decoder_tree[NUMBER_OF_REGIONS][DIFF_REGION_POWER_LEVELS][2] = { /* "rms_table"? */
    {{  1,  2},{  3,  4},{  5,  6},{  7,  8},{  9, 10},{ 11,-12},{-11,-10},{ -8, -9},{ -7, -6},{-13, 12},{ -5, -4},{  0, 13},{ -3,-14},{ -2, 14},{ -1, 15},{-15, 16},{-16, 17},{-17, 18},{ 19, 20},{ 21, 22},{-18,-19},{-20,-21},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,  6},{  7,  8},{-10, -9},{ -8,-11},{ -7, -6},{  9, -5},{ 10,-12},{ -4, 11},{-13, -3},{ 12, -2},{ 13,-14},{ -1, 14},{ 15,-15},{  0, 16},{-16, 17},{-17, 18},{-18, 19},{ 20, 21},{ 22,-19},{-20,-21},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,  6},{  7,  8},{  9, 10},{-12, 11},{-11,-13},{-10, -9},{ 12,-14},{ -8, -7},{-15, -6},{ 13, -5},{-16, -4},{ 14,-17},{ 15, -3},{ 16,-18},{ -2, 17},{ 18,-19},{ -1, 19},{-20, 20},{  0, 21},{ 22,-21},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,  6},{-11,-10},{  7,-12},{  8, -9},{  9,-13},{-14, 10},{ -8,-15},{-16, 11},{ -7, 12},{-17, -6},{ 13, 14},{-18, 15},{ -5, -4},{ 16, 17},{ -3, -2},{-19, 18},{ -1, 19},{-20, 20},{ 21, 22},{  0,-21},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,  6},{-12,-11},{-13,  7},{  8,-14},{-10,  9},{ 10,-15},{ -9, 11},{ -8, 12},{-16, 13},{ -7, -6},{-17, 14},{ -5,-18},{ 15, -4},{ 16,-19},{ 17, -3},{-20, 18},{ -2, 19},{-21, 20},{  0, 21},{ 22, -1},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,  6},{-11,  7},{-12,-10},{-13, -9},{  8,  9},{-14, -8},{ 10,-15},{ -7, 11},{-16, 12},{ -6,-17},{ 13, 14},{ -5, 15},{-18, 16},{ -4, 17},{ -3,-19},{ 18, -2},{-20, 19},{ -1, 20},{  0, 21},{ 22,-21},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,-12},{  6,-11},{-10,-13},{ -9,  7},{  8,-14},{  9, -8},{-15, 10},{ -7,-16},{ 11, -6},{ 12,-17},{ 13, -5},{-18, 14},{ 15, -4},{-19, 16},{ 17, -3},{-20, 18},{ 19, 20},{ 21, 22},{  0, -2},{ -1,-21},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,-12},{  6,-13},{-11,-10},{  7,-14},{  8, -9},{  9,-15},{ -8, 10},{ -7,-16},{ 11, 12},{ -6,-17},{ -5, 13},{ 14, 15},{-18, -4},{-19, 16},{ -3, 17},{ 18, -2},{-20, 19},{ 20, 21},{ 22,  0},{ -1,-21},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,  6},{-11,-10},{-12, -9},{  7,  8},{-13, -8},{  9,-14},{ -7, 10},{ -6,-15},{ 11, 12},{ -5,-16},{ 13, 14},{-17, 15},{ -4, 16},{ 17,-18},{ 18, -3},{ -2, 19},{ -1,  0},{-19, 20},{-20, 21},{ 22,-21},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,  6},{-11,  7},{-10,-12},{ -9,  8},{ -8,-13},{  9, -7},{ 10,-14},{ -6, 11},{-15, 12},{ -5, 13},{-16, -4},{ 14, 15},{-17, -3},{-18, 16},{ 17,-19},{ -2, 18},{-20, 19},{ -1, 20},{ 21, 22},{  0,-21},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,-12},{  6,-11},{  7,  8},{-10,-13},{ -9,  9},{ -8,-14},{ 10, -7},{ 11,-15},{ -6, 12},{ -5, 13},{ -4,-16},{ 14, 15},{ -3,-17},{ 16, 17},{-18, -2},{ 18,-19},{ -1, 19},{-20, 20},{-21, 21},{ 22,  0},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{  5,-12},{-13,  6},{-11,  7},{-14,  8},{-10,  9},{-15, -9},{ -8, 10},{ -7,-16},{ 11, -6},{ 12, -5},{-17, 13},{ 14,-18},{ 15, -4},{ 16,-19},{ 17, -3},{ 18, -2},{ 19, -1},{-20, 20},{ 21, 22},{  0,-21},{-22,-23},{  0,  0}},
    {{  1,  2},{  3,  4},{-12,  5},{-11,-13},{  6,-14},{-10,  7},{  8,-15},{ -9,  9},{-16, 10},{ -8,-17},{ 11, 12},{ -7,-18},{ -6, 13},{ 14, -5},{ 15,-19},{ -4, 16},{-20, 17},{ 18, 19},{ 20, 21},{ 22,  0},{ -1, -3},{ -2,-21},{-22,-23},{  0,  0}},
};

/* vs refdec: same table */
static const int16_t mlt_quant_centroid[NUM_CATEGORIES][NUM_BINS] = { /* "mlt_q" */
    {    0, 1606, 3119, 4586, 6049, 7502, 8941,10406,11851,13292,14736,16146,17566,19351,    0,    0},
    {    0, 2229, 4341, 6401, 8471,10531,12583,14588,16673,18924,    0,    0,    0,    0,    0,    0},
    {    0, 3055, 5998, 8929,11806,14680,17680,    0,    0,    0,    0,    0,    0,    0,    0,    0},
    {    0, 4121, 8192,12259,16322,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0},
    {    0, 5413,11071,16315,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0},
    {    0, 6785,14300,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0},
    {    0, 8044,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0},
    {    0, 8019,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0}
};

/* vs refdec: Namco uses a stack array with these values */
static const int16_t expected_bits_table[NUM_CATEGORIES] = {
    52, 47, 43, 37, 29, 22, 16,   0
};

/* vs refdec: Namco uses positive values *2 but I'm not sure what they are for (some index access) 
 * so these are the refdec values */
static const int16_t mlt_decoder_tree_category_0[180][2] = { /* "reasion_huffman_table"? */
    {   1,   0},{   2,   3},{   4,   5},{   6,   7},{   8,   9},{  -1, -14},{  10,  11},{  12,  13},
    {  14,  15},{  16,  17},{  18,  19},{ -15,  20},{  21,  22},{  23, -28},{  24,  -2},{  25,  26},
    {  27,  28},{  29,  30},{  31,  32},{ -29,  33},{ -16,  34},{  -3,  35},{  36,  37},{ -42,  38},
    {  39,  40},{  41,  42},{  43,  44},{ -17,  45},{ -43,  46},{  47,  48},{  -4,  49},{ -56,  50},
    {  51,  52},{  53,  54},{  55,  56},{ -57,  -5},{ -30,  57},{  58,  59},{ -18,  60},{  61, -70},
    {  62,  63},{  64,  -6},{  65,  66},{ -44,  67},{ -71,  68},{  69,  70},{ -19, -31},{ -84,  71},
    {  72,  73},{  74,  75},{  76,  77},{  -7,  78},{  79, -20},{  80,  81},{ -85,  82},{ -98,  83},
    { -58,  84},{  85, -32},{ -99,  86},{  -8,  87},{  88,  89},{ -72, -45},{  90, -33},{  91,-112},
    { -21,  92},{ -59,-113},{ -46,  93},{  -9,  94},{ -22,  95},{  96,  97},{  98,  99},{ -23, -86},
    { 100, 101},{ -34, -73},{ 102,-126},{-127, -35},{ 103, -47},{ 104, 105},{ 106, 107},{-140,-100},
    {-114, -87},{ 108, 109},{ 110, 111},{-141, -60},{ 112, -48},{ 113, -24},{ -10, -61},{ 114,-101},
    { 115, 116},{ -74, -36},{ 117,-128},{ 118, -62},{ 119, 120},{ -37, 121},{ -11, -49},{ -88, 122},
    { 123,-115},{-154, -25},{-142, 124},{-155,-129},{ 125, -50},{ 126, 127},{ -76, -75},{ 128, 129},
    { -63, -77},{-102, -39},{ -38, 130},{ -51, 131},{ -89,-116},{-117,-156},{ 132, -52},{ -78, 133},
    { 134,-103},{ 135, 136},{-143, -65},{ 137, -64},{-130,-131},{ -90, 138},{-104, -91},{ -92, 139},
    {-169,-183},{ -26,-118},{ 140, 141},{-144, -66},{ -12, 142},{-168, 143},{-105,-157},{ 144,-182},
    { 145, 146},{ -79, 147},{ -53,-170},{ 148, 149},{ -27,-145},{ 150, -80},{-106, -13},{-132, -67},
    {-158, -40},{-119, 151},{ 152,-107},{ 153, 154},{ -41,-184},{ 155, 156},{ -54, 157},{-171, 158},
    { -94, 159},{-134,-146},{ -93,-133},{-159,-108},{ 160, -81},{ 161,-160},{ 162, -68},{-120,-122},
    {-172, 163},{ -55, -95},{ 164,-109},{-161, -82},{-173,-185},{ 165, -69},{-147,-186},{ 166, 167},
    {-121, -96},{ 168,-148},{-174, 169},{ 170,-136},{ -83, 171},{ 172, 173},{-135,-110},{-187, 174},
    {-149,-150},{ 175,-123},{-162,-163},{ -97,-175},{-188, 176},{ 177, 178},{ 179,-111},{-151,-124},
    {-137,-177},{-176,-125},{-164,-138},{-189,-190},};
static const int16_t mlt_decoder_tree_category_1[93][2] = {
    {   1,   0},{   2,   3},{   4,   5},{   6,   7},{   8, -10},{  -1,   9},{  10,  11},{  12,  13},
    { -11,  14},{  15,  16},{  17,  18},{ -20,  -2},{  19,  20},{ -21,  21},{  22,  23},{ -12,  24},
    {  25,  26},{  27,  28},{  29,  30},{ -30,  31},{ -31,  -3},{  32, -22},{  33, -13},{  34,  35},
    {  36,  37},{  38,  39},{  40,  -4},{ -41, -14},{  41, -40},{ -32,  42},{  43, -23},{  44,  45},
    {  46,  47},{  48,  -5},{ -51, -50},{ -42,  49},{ -33,  50},{ -15,  51},{  52,  53},{  54, -24},
    {  55, -43},{  56, -52},{  57, -61},{ -60,  58},{ -25,  59},{ -16, -34},{  -6,  60},{ -62,  61},
    { -71,  62},{ -35,  -7},{  63, -72},{ -53, -17},{  64, -44},{ -26, -70},{  65, -45},{ -36,  66},
    { -63,  67},{ -80, -54},{ -81,  68},{ -27,  69},{  70, -82},{ -18,  71},{  72, -55},{  73, -64},
    {  74, -73},{  75, -46},{ -37,  76},{ -91,  -8},{  -9,  77},{ -90, -83},{  78, -28},{  79, -56},
    { -65, -38},{ -74,  80},{ -19, -57},{ -92,  81},{ -47, -48},{  82, -66},{  83, -29},{ -84,  84},
    { -75, -85},{ -67, -93},{ -39,  85},{ -76,  86},{ -58,  87},{  88, -49},{ -94,  89},{  90, -68},
    {  91, -78},{ -86, -59},{ -77, -95},{  92, -69},{ -87, -96},};
static const int16_t mlt_decoder_tree_category_2[47][2] = {
    {   1,   0},{   2,   3},{   4,   5},{   6,  -7},{  -1,   7},{  -8,   8},{   9,  10},{  11,  12},
    {  13, -14},{ -15,  -9},{  -2,  14},{  15,  16},{  17,  18},{  19, -16},{  20, -22},{ -10,  21},
    { -21,  -3},{  22,  23},{  24,  25},{ -23, -17},{  26,  27},{  28, -29},{ -11, -28},{  29,  30},
    {  -4, -24},{ -30,  31},{  32, -18},{  33, -35},{ -36,  34},{ -31, -12},{  35, -25},{  -5, -37},
    {  36,  37},{ -42,  38},{ -19, -43},{ -32,  39},{ -13, -38},{ -26, -20},{  40,  -6},{ -44,  41},
    {  42, -39},{ -33, -45},{  43, -27},{  44, -46},{  45, -34},{ -40,  46},{ -41, -47},};
static const int16_t mlt_decoder_tree_category_3[519][2] = {
    {   1,   2},{   3,   4},{   5,   0},{   6,   7},{   8,   9},{  10,  11},{  12,  13},{  14,  15},
    {  16,  17},{-125,  18},{  -1,  19},{  20,  21},{  22,  23},{  24,  25},{  -5, -25},{  26,  27},
    {  -6,-150},{  28,  29},{  30,  31},{  32,  33},{  34, -30},{  35,  36},{  37,  38},{  39, -31},
    {-126,-155},{  40,  41},{-156,  42},{  43,-130},{  44,-131},{-151, -26},{  45,  46},{-250,  47},
    {  48,  49},{  50,  51},{  52,-275},{  53,  54},{  -2,  -7},{  55,  56},{  57,  58},{  59,  60},
    {  61,  62},{  63,  64},{  65,  66},{  67,  68},{  69,  70},{  71, -50},{  72,-180},{  73,  74},
    {  75,  76},{  77, -55},{  78,-175},{  79, -36},{  80,  81},{ -35, -10},{  82,  83},{-280,  84},
    { -11,  85},{  86, -32},{  87,  88},{  89,-161},{  90,-276},{  91,  92},{-281,  93},{  -8,  94},
    {  95,  96},{  97,-157},{-181,-400},{-132,  98},{-375,  99},{-160, 100},{-127, 101},{ -27, 102},
    { 103,-251},{ -56, 104},{ 105,-256},{-300,  -3},{-152,-255},{ 106, 107},{ -37, 108},{-305, 109},
    {-176, 110},{-136, 111},{ -12, 112},{ 113, 114},{ 115,-135},{ 116, 117},{-162, 118},{ -16, -51},
    {-186, 119},{ 120, 121},{ 122, 123},{ -41, 124},{ -61, 125},{ 126, 127},{ 128, 129},{ 130, -60},
    { 131, 132},{-306, 133},{ 134,-205},{-405, 135},{ 136, 137},{ 138, 139},{-185, 140},{ 141,-500},
    { -15, 142},{ 143, -80},{ -75, -40},{-301, 144},{ 145, 146},{-200, 147},{ 148, 149},{ 150, 151},
    { 152,-525},{ 153,-177},{-425, 154},{ 155, -13},{-430, 156},{ 157,-406},{ 158, 159},{-206,-380},
    { 160, 161},{ 162, 163},{ 164,-182},{-137, 165},{-286, 166},{ 167,-401},{ 168, 169},{ -42, -33},
    { 170,-166},{ -57,-325},{ 171,-187},{ -38, 172},{ 173, 174},{-165,-330},{  -4,-282},{ 175,-257},
    {-261,-311},{-376, 176},{ 177, 178},{ -28, 179},{ 180,  -9},{-285, 181},{ 182, 183},{ 184,-277},
    { 185,-133},{-310, -81},{ -85, 186},{-158,-210},{ -17, 187},{ 188, 189},{ 190, -52},{-141, 191},
    { 192,-128},{-191, -20},{ 193,-140},{ 194, 195},{-211,-260},{ 196, 197},{ 198, 199},{ 200, -66},
    {-201,-225},{-381, 201},{ 202, 203},{ 204, 205},{ 206, 207},{-163,-287},{ 208,-100},{ 209, 210},
    { 211, 212},{ 213,-252},{-105, -76},{ 214, 215},{ 216, -21},{ -86, -62},{-307, 217},{ -65,-455},
    {-550, 218},{ 219, 220},{ 221, 222},{ 223, 224},{ 225,-230},{-142, 226},{-302,-426},{-431, 227},
    { 228, 229},{ 230,-190},{-402, -46},{-153,-450},{-505, 231},{ 232, 233},{ 234, 235},{ 236, 237},
    { 238, 239},{-262, -29},{ 240, 241},{ 242, 243},{-167, -67},{-331,-530},{ 244, 245},{ 246, 247},
    { 248, 249},{ 250, 251},{ 252, 253},{ 254, 255},{ 256, 257},{ 258, 259},{ 260, 261},{ 262,-336},
    { 263,-171},{-192,-207},{-258,-138},{ 264, 265},{ 266, 267},{ 268, 269},{ 270, 271},{ 272, 273},
    { 274, -45},{-335,-411},{ -43, -18},{-265, -71},{-316,-326},{-350,-407},{-146, -14},{ 275, 276},
    { 277, 278},{ 279, 280},{ 281,-216},{ -34,-283},{-291,-312},{-410,-168},{-555, 282},{ -70, -53},
    {-235, -87},{ -77,-183},{-315,-332},{-178, -58},{ 283, 284},{ 285, 286},{ 287, 288},{ 289, 290},
    { 291, 292},{ 293, 294},{ 295, 296},{ 297, 298},{-202,-226},{-170,-267},{-134,-290},{-355,-385},
    {-386, -47},{-526,-196},{ 299, 300},{ 301, 302},{ 303, 304},{ 305, 306},{ 307, 308},{ 309, 310},
    { 311, 312},{ 313, 314},{ 315, 316},{ 317, 318},{ 319, 320},{ 321, 322},{ 323, 324},{ 325,-111},
    {-231,-253},{ -91, -82},{-172,-145},{ -22,-317},{ -90,-356},{-382,-159},{ 326, 327},{ 328, 329},
    { 330, 331},{ 332, 333},{ 334, 335},{-106,-263},{-278,-215},{-110, -39},{-101,-377},{-129, -63},
    {-436,-195},{-506,-531},{ 336,-212},{-154,-266},{ -59,-288},{-292,-303},{-337,-432},{-188,-451},
    {-456,-460},{-501,-236},{-551, 337},{ 338, 339},{ 340, 341},{ 342, 343},{ 344, 345},{ 346, 347},
    { 348, 349},{ 350, 351},{ 352, 353},{ 354, 355},{ 356, 357},{ 358, 359},{ 360, 361},{ 362, 363},
    { 364, 365},{ 366, 367},{ 368, 369},{ 370, 371},{ 372, 373},{ 374, 375},{ 376, 377},{ 378, 379},
    { 380, 381},{ 382, 383},{ 384, 385},{ 386, 387},{ 388, 389},{ 390, 391},{ 392, 393},{ 394, 395},
    { 396, 397},{ 398, 399},{ 400, 401},{ 402, 403},{ 404, 405},{ 406, 407},{ -72,-272},{-309,-333},
    {-340,-360},{ -68,-387},{-184,-416},{-427,-147},{-435,-437},{-115,-480},{-510,-532},{-164,-556},
    { 408,-295},{-296,-297},{-107,-313},{-193,-173},{-320,-327},{-341,-351},{-352,-143},{-378, -19},
    {-403,-412},{-268, -54},{ -83,-441},{-442,-457},{-475, -44},{ -97,-511},{-515,-208},{-527,-528},
    {-237,-536},{-552, 409},{ 410, 411},{ 412, 413},{ 414, 415},{ 416, 417},{ 418, 419},{ 420, 421},
    { 422, 423},{ 424, 425},{ 426, 427},{ 428, 429},{ 430, 431},{ 432, 433},{ 434, 435},{ 436, 437},
    { 438, 439},{ 440, 441},{ 442, 443},{ 444, 445},{ 446, 447},{ 448, 449},{ 450, 451},{ 452, 453},
    { 454, 455},{ 456, 457},{ 458, 459},{ 460, 461},{ 462, 463},{ 464, 465},{ 466, 467},{ 468, 469},
    { 470, 471},{ 472, 473},{ 474, 475},{ 476, 477},{ 478, 479},{ 480, 481},{ 482, 483},{ 484, 485},
    { 486, 487},{ 488, 489},{ 490, 491},{ 492, 493},{ 494, 495},{ 496, 497},{ 498, 499},{ 500, 501},
    { 502, 503},{ 504, 505},{ 506, 507},{ 508, 509},{ 510, 511},{ 512, 513},{ 514, 515},{ 516, 517},
    { 518,-104},{ -84,-218},{-318,-319},{-117,-321},{-322,-323},{-219,-174},{-243,-328},{-329, -94},
    {-228,-194},{-240,-334},{-102,-229},{-169,-338},{-339,-116},{-289,-342},{-343,-345},{-346,-347},
    { -23,-203},{-214,-353},{-204,-220},{-357,-358},{-264,-361},{-362,-363},{-365,-366},{-367, -92},
    {-245,-121},{-293,-379},{-108,-232},{-221,-383},{-384,-233},{-294,-241},{-388,-389},{-390,-391},
    {-392,-393},{-394,-395},{-396,-397},{-398, -24},{-109,-149},{-242,-404},{ -64, -79},{ -89,-408},
    {-409,-213},{-120,-113},{-413,-414},{-415, -96},{-417,-418},{-419,-420},{-421,-422},{-423,-298},
    { -69,-269},{-428,-429},{ -78,-270},{ -88,-433},{-434,-271},{-234,-259},{-438,-439},{-440,-227},
    {-179,-443},{-445,-446},{-447,-223},{-238,-452},{-453,-454},{-273,-254},{-246,-458},{-459, -48},
    {-461,-462},{-463,-465},{-466,-467},{-468,-470},{-471,-304},{-476,-477},{-478,-112},{-481,-482},
    {-483,-485},{-486,-487},{-490,-491},{-103,-118},{-502,-503},{-504,-189},{ -93,-507},{-508,-509},
    {-148,-139},{-512,-513},{-308,-516},{-517,-518},{-520,-521},{ -73, -98},{ -95, -49},{-529,-222},
    {-217,-197},{-533,-534},{-535,-284},{-537,-538},{-540,-541},{-542,-543},{-545,-546},{-144,-198},
    {-314,-553},{-209,-279},{-557,-558},{-560,-561},{-562,-563},{-565,-566},{-567,-575},{-576,-577},
    {-578,-580},{-581,-582},{-583,-585},{-586,-587},{-590,-591},{-600,-601},{-605,-606},};
static const int16_t mlt_decoder_tree_category_4[208][2] = {
    {   1,   2},{   3,   0},{   4,   5},{   6,   7},{   8,   9},{  10,  11},{  12, -64},{  -1,  13},
    {  14, -16},{  -4,  15},{  16,  17},{  18, -80},{  -5,  19},{  20,  21},{ -20,  22},{  23, -65},
    { -84, -21},{ -68,  24},{ -17,  25},{  26,  27},{  28, -81},{ -69, -85},{  29,  30},{  31,  32},
    {-128,  33},{  34,  35},{  -2,  36},{  37,  38},{-144,  39},{  40,  -6},{  41,  42},{ -32,  43},
    {  44,  -8},{  45, -25},{ -96,  46},{  47,-100},{  -9,  48},{  49, -36},{  50, -24},{  51,  52},
    {  53,-148},{  54,  55},{ -22,  56},{  57,  58},{-132, -89},{  59,  60},{-101,  61},{ -37,  62},
    { -18,  63},{ -88,-129},{ -66, -70},{ -97,  64},{ -72, -73},{  65,-145},{-149, -86},{  66, -33},
    {  67,-133},{  68,  69},{  70,  71},{-192,  72},{  73,-160},{ -82,  74},{-164,  75},{ -10,  76},
    {  77,-208},{  78, -40},{  79,  80},{  -3,  81},{  -7,  82},{  83,  84},{-104,  85},{  86, -26},
    {  87,-105},{  88,-112},{  89,  90},{  91, -41},{  92,  93},{  94,  95},{ -48,  96},{ -90,  97},
    {  98, -28},{ -52,  99},{ -12, 100},{ 101, -74},{ -13,-116},{-161, 102},{ 103, -29},{-102, 104},
    {-152,-165},{ 105, 106},{ 107, 108},{ 109, 110},{ 111,-212},{ 112, 113},{-136, 114},{ 115,-137},
    { 116, -23},{ -19,-153},{ -98,-134},{-196, 117},{ 118, 119},{ -38,-193},{-113,-150},{-209, 120},
    { 121, -93},{ -83, 122},{ 123, 124},{ 125, 126},{ 127, 128},{ 129, 130},{ 131, -34},{-146, -53},
    { 132, 133},{ 134, 135},{ 136, 137},{ 138,-130},{ -49, 139},{ 140, 141},{-117, -42},{ -67, -92},
    { 142, -87},{ -77,-197},{ -71, 143},{ 144, 145},{ 146, 147},{ 148, 149},{ 150, 151},{ 152, 153},
    { 154, 155},{ 156, 157},{ 158, 159},{ 160, 161},{ 162, 163},{ 164, 165},{ 166, 167},{ 168, 169},
    {-108, -76},{-168,-169},{-176, -44},{-224, -56},{ -45,-180},{ -11,-106},{-213, 170},{ 171, 172},
    { 173, 174},{ 175, 176},{ 177, 178},{ 179, 180},{ 181, 182},{ 183, 184},{ 185, 186},{ 187, 188},
    { 189, 190},{ 191, 192},{ 193, 194},{ 195, 196},{ 197, 198},{ 199, 200},{ 201, 202},{ 203, 204},
    { 205, 206},{ 207,-131},{ -30, -27},{ -43,-151},{ -75,-154},{-156,-162},{-109,-194},{-198,-201},
    {-114,-225},{-228,-229},{-141,-142},{ -94,-124},{ -95,-147},{-115,-125},{ -54, -55},{-107, -58},
    { -39,-155},{-121,-157},{-158,-103},{ -14,-122},{-163, -51},{ -57,-166},{-167, -46},{-110,-170},
    {-172,-173},{ -61,-177},{-178, -99},{-181,-182},{-184,-185},{-118, -35},{ -15,-195},{ -31, -60},
    {-135,-199},{-200, -79},{-202,-204},{-205,-119},{ -91,-210},{-211, -78},{-120,-214},{-215,-216},
    {-217,-218},{-220,-221},{ -50,-138},{-226,-139},{-140,-230},{-232,-233},{-240,-241},{-244,-245},};
static const int16_t mlt_decoder_tree_category_5[191][2] = {
    {   1,   2},{   0,   3},{   4,   5},{   6,   7},{   8,   9},{  10,  11},{ -81,  -1},{  12,  13},
    {  14, -27},{  -3,  -9},{  15,  16},{  17,  18},{  19,  20},{-108,  21},{  -4,  22},{  23, -36},
    { -12,  24},{ -82,  25},{  26, -84},{  27, -90},{ -10, -30},{  28,  29},{  30, -28},{  31,-117},
    { -13,  32},{ -39,  33},{  34,-109},{  35, -93},{ -85,-111},{ -37,  36},{ -31,  37},{ -91,  38},
    {  39,  40},{ -40,-120},{  41,  42},{-118,  43},{ -94,  44},{-112,-162},{  45,  46},{  -2,  47},
    {  48,  49},{-121,-189},{  50, -54},{  51,  52},{  53, -18},{  54,  55},{  -6,  56},{  57,  -5},
    {-135,  58},{  59,  60},{  61,  62},{ -63,  63},{  64,  -7},{ -15,  65},{  66,  67},{ -45,  68},
    {  69,  70},{  71, -21},{  72,  73},{  74,  75},{  76,  77},{-163,  78},{  79,-171},{-144,  80},
    { -48,  81},{ -57,  82},{  83,  84},{-165,  85},{ -16,-198},{  86,  87},{ -11,  88},{  89, -99},
    {  90, -83},{ -19,  91},{  92,  93},{  94,  95},{  96,  97},{  98,  99},{ -87, 100},{ 101, 102},
    {-190, -66},{ -33,-192},{ 103, 104},{ 105, 106},{-102, -42},{ 107,-126},{ 108, -29},{-129, -46},
    { -86, -14},{-114, -32},{-172, 109},{ 110, -58},{ -34,-138},{ 111, 112},{ 113, 114},{ 115, 116},
    { 117, 118},{ 119, 120},{-127,-166},{-174, 121},{ 122, 123},{ 124, 125},{ -88, -96},{ 126,-100},
    { -38,-110},{ -22,-136},{ -55,-139},{-201, 127},{ -64,-193},{ 128, -49},{-175,-199},{ 129, 130},
    { 131, 132},{ 133, 134},{ 135, 136},{ 137, 138},{ 139, 140},{ 141, 142},{ 143, 144},{ 145, 146},
    { 147, 148},{ 149, 150},{-103, -92},{ -43,-130},{-145,-147},{-148, -41},{-216,-115},{-119,-123},
    { -95, 151},{ 152, 153},{ 154, 155},{ 156, 157},{ 158, 159},{ 160, 161},{ 162, 163},{ 164, 165},
    { 166, 167},{ 168, 169},{ 170, 171},{ 172, 173},{ 174, 175},{ 176, 177},{ 178, 179},{ 180, 181},
    { 182, 183},{ 184, 185},{ 186, 187},{ 188, 189},{ 190,-153},{-180,  -8},{ -97, -24},{-122,-113},
    {-124,-125},{ -67, -44},{-128, -69},{-106,-131},{-132,-133},{ -61, -73},{-137,-116},{ -89,-140},
    {-141,-142},{ -23, -25},{-146, -17},{-104,-149},{-150,-151},{ -52,-154},{-156,-157},{ -76, -70},
    {-164, -51},{ -72,-167},{-168,-169},{ -47, -20},{-173, -59},{-101,-176},{-177,-178},{ -68,-181},
    {-183,-184},{ -35, -60},{-191, -98},{ -56,-194},{-195,-196},{ -75, -65},{-200,-105},{-202,-203},
    {-204,-205},{-207,-208},{-210,-211},{ -50,-217},{-219,-220},{-225,-226},{-228,-229},};
static const int16_t mlt_decoder_tree_category_6[31][2] = {
    {   1,   0},{   2,   3},{   4,   5},{   6,   7},{   8, -16},{  -1,  -8},{  -2,  -4},{   9,  10},
    {  11,  12},{  13,  14},{  15,  16},{  17, -24},{  -3, -12},{  -6,  18},{  19, -20},{ -10,  -5},
    { -17,  -9},{ -18,  20},{  21,  22},{  23,  24},{  25, -28},{  26,  -7},{ -14, -22},{ -26, -11},
    {  27, -19},{ -25, -13},{ -21,  28},{  29, -30},{ -27,  30},{ -15, -29},{ -23, -31},};

static const int16_t *table_of_decoder_tables[NUM_CATEGORIES-1] = {
    (const int16_t *)mlt_decoder_tree_category_0,
    (const int16_t *)mlt_decoder_tree_category_1,
    (const int16_t *)mlt_decoder_tree_category_2,
    (const int16_t *)mlt_decoder_tree_category_3,
    (const int16_t *)mlt_decoder_tree_category_4,
    (const int16_t *)mlt_decoder_tree_category_5,
    (const int16_t *)mlt_decoder_tree_category_6,
};


/* vs refdec: same table */
static const int16_t region_standard_deviation_table[REGION_POWER_TABLE_SIZE] = { /* "rnd_reg"? */
        0,   0,   0,    0,    0,    0,    0,    0,
        0,   0,   0,    0,    0,    0,    0,    0,
        0,   0,   0,    0,    0,    0,    1,    1,
        1,   1,   2,    3,    4,    6,    8,   11,
       16,  23,  32,   45,   64,   91,  128,  181,
      256, 362, 512,  724, 1024, 1448, 2048, 2896,
     4096,5793,8192,11585,16384,23170,    0,    0,
        0,   0,   0,    0,    0,    0,    0,    0,
};

/* the following tables don't use last index since category 7 isn't quantized */

/* vs refdec: same table but last index is 20 */
static const int16_t number_of_vectors[NUM_CATEGORIES] = {
    10, 10, 10, 5, 5, 4, 4, 0,
};
/* vs refdec: same table but last index is 1 */
static const int16_t vector_dimension[NUM_CATEGORIES] = { /* "vd_inv"? */
    2, 2, 2, 4, 4, 5, 5, 0,
};

/* vs refdec: pre-adds one instead of in runtime and last index is 1 */
static const int16_t max_bin_plus1[NUM_CATEGORIES] = { /* "kmax_p1" */
    14, 10, 7, 5, 4, 3, 2, 0,
};

/* vs refdec: pre-scaled x2 (cat3 subs -1 and cat5/7 -2 too) */
static const uint16_t max_bin_plus_one_inverse_scaled[8] = { /* "kmax_p1_inv" */
    4682, 6554, 9363, 13108, 16384, 21846, 32768, 0,
};

#endif
